<?php


namespace support\utils;


use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use SplFileInfo;

class FileUtil
{
    /**
     * 文件目录迭代器
     * @param array $dirs 目录地址数组
     * @param callable $callback $callback($fileUrl, SplFileInfo $fileInfo)
     */
    static function fileIterator(array $dirs, callable $callback)
    {
        if (!$dirs) {
            return;
        }
        foreach ($dirs as $dir) {
            $dir_iterator = new RecursiveDirectoryIterator($dir);
            $iterator = new RecursiveIteratorIterator($dir_iterator);
            foreach ($iterator as $fileUrl) {
                if (is_dir($fileUrl)) {
                    continue;
                }
                $fileInfo = new SplFileInfo($fileUrl);
                $callback && $callback($fileUrl, $fileInfo);
            }
        }

    }
}